package cn.com.nes.site.service.workOrder.impl;

import cn.com.nes.common.exception.BusinessException;
import cn.com.nes.site.service.workOrder.impl.WorkOrderBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class WorkOrderServiceStrategyFactory {

    @Autowired
    private List<WorkOrderBuilder> workOrderBuilders;


    private static Map<String, WorkOrderBuilder>  workOrderBuilderMap;

    @PostConstruct
    public void init() {
        workOrderBuilderMap = workOrderBuilders.stream().collect(Collectors.toMap(WorkOrderBuilder::getType, t -> t));
    }

    public WorkOrderBuilder getCustomerBuilderService(String type) {
        WorkOrderBuilder workOrderBuilder = workOrderBuilderMap.get(type);
        if (workOrderBuilder == null) {
            throw new BusinessException("未匹配的处理逻辑！");
        }
        return workOrderBuilder;
    }


}
